package com.amigo.online.provider.adv.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import com.amigo.online.common.param.adv.bo.AdvTantanInitBO;

@Mapper
public interface AdvTantanApplyMapper {

    @Select("select a.* from adv_tantan_apply_tbl a, adv_tantan_stock_tbl s where a.start_time > #{currentMillis} and"
            + " a.end_time < #{currentMillis} and a.status = 1 and b.remaining_number >0")
    @Results({
            @Result(property = "areaList", column = "id", javaType = List.class
                    , many = @Many(select = "com.amigo.online.provider.adv.mapper.AdvApplyAreaMapper.getTantanApplyAreaIdsByApplyId"))
    })
    List<AdvTantanInitBO> listFindTodayUsableResourceByTime(@Param("currentMillis") long currentMillis);


    @Select("select id, target_user_sex_type as sexType, target_user_age_type as ageType, target_area_type as areaType,"
            + " total_number as remainingNumber from adv_tantan_apply_tbl where start_time = #{timeMillis} and status = 1 ")
    @Results({
            @Result(id = true, property = "id", column = "id"),
            @Result(property = "areaList", column = "id", javaType = List.class
                    , many = @Many(select = "com.amigo.online.provider.adv.mapper.AdvApplyAreaMapper.getTantanApplyAreaIdsByApplyId"))
    })
    List<AdvTantanInitBO> listFindTomorrowAdvDeliveryPlanByStartTime(@Param("timeMillis") long tomorrow);

    @Select("select id, target_user_sex_type as sexType, target_user_age_type as ageType, target_area_type as areaType,"
            + " total_number as remainingNumber from adv_tantan_apply_tbl  where end_time = #{timeMillis} and status = 1")
    @Results({
            @Result(id = true, property = "id", column = "id"),
            @Result(property = "areaList", column = "id", javaType = List.class
                    , many = @Many(select = "com.amigo.online.provider.adv.mapper.AdvApplyAreaMapper.getTantanApplyAreaIdsByApplyId"))
    })
    List<AdvTantanInitBO> listFindTomorrowAdvSettlePlanByEndTime(@Param("timeMillis") long today);

}
